package org.addressBook.servlet;

import org.addressBook.service.TbUserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class PersonInfoServlet extends HttpServlet {
    TbUserService tbUserService = new TbUserService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oldName = (String) request.getSession().getAttribute("name");

        String userName = request.getParameter("newName");
        String email = request.getParameter("mail");
        String password = request.getParameter("password");

        try {
            tbUserService.PersonInfoService(oldName,userName,email,password);
            request.getSession().setAttribute("name",userName);
            request.getRequestDispatcher("/manage.jsp").forward(request, response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        super.doPost(request, response);
    }
}
